﻿@{
    ViewBag.Title = "体检套餐管理";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

    var data = ViewBag.Data as List<LPY.LeHealth.Model.Combo>;
    var hos = ViewBag.Hospitals as List<LPY.LeHealth.Model.Hospital>;
    var combos = ViewBag.Combos as List<LPY.LeHealth.Model.ComboType>;
    var items = ViewBag.Items as List<LPY.LeHealth.Model.PhysicalItem>;
}

@section Header{
    <link href="~/Asset/font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet" />
    <script src="~/Asset/esimakin-twbs-pagination/jquery.twbsPagination.min.js"></script>

    <link href="~/Asset/bootstrap-multiselect/bootstrap-multiselect.css" rel="stylesheet" />
    <script src="~/Asset/bootstrap-multiselect/bootstrap-multiselect.js"></script>
}

<div class="content">
    <div class="row">
        <div class="col-md-2">
            <div class="list-group">
                <a href="@Url.Action("PhysicalItem","Admin")" class="list-group-item">体检项管理</a>
                @*<a href="@Url.Action("PhysicalSingle", "Admin")" class="list-group-item">单项体检管理</a>*@
                <a href="@Url.Action("PhysicalCombo", "Admin")" class="list-group-item active">体检套餐管理</a>
            </div>
        </div>

        <div class="col-md-10">
            <div class="page-header clearfix" style="padding:10px;">
                <h4 class="pull-left">体检管理</h4>
                <!--操作按钮-->
                <div class="pull-right">
                    <a class="btn btn-success btn-sm" data-toggle="modal" data-target="#modal_add_hospital">添加体检套餐</a>
                </div>
            </div>

            <!--内容区域-->
            @*<form id="user-search-form" class="form-inline well well-sm" action="/Exam/QueryExam" method="post" novalidate="">
                    <div class="form-group">
                        <input type="text" id="keyword" name="ExamName" class="form-control" value="" placeholder="添加相关词">
                    </div>
                    <button class="btn btn-primary" type="submit">搜索</button>
                </form>*@

            <table id="user-table" class="table table-striped table-hover" data-search-form="#user-search-form">
                <thead>
                    <tr>
                        <td>名称</td>
                        <td>简介</td>
                        <td>适宜人群</td>
                        <td>价格</td>
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in data)
                    {
                        <tr>
                            <td style="width:20%;">@item.Name</td>
                            <td>@item.Details</td>
                            <td style="width:10%;">@item.Appropriate</td>
                            <td style="width:10%;">@Math.Round(item.Price, 2)</td>
                            <td style="width:10%;">
                                <div class="btn-group">

                                    <a href="#" class="btn btn-default btn-sm">管理</a>
                                    <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                        <span class="caret"></span>
                                    </a>

                                    <ul class="dropdown-menu">
                                        <li><a class="edit" href="#" data-id="@item.Id">编辑</a></li>
                                        <li><a class="delete" href="#" data-id="@item.Id">删除</a></li>
                                    </ul>
                                </div>
                            </td>
                        </tr>
                    }

                </tbody>
            </table>

            <!--分页-->
            <nav class=" text-center">
                <ul id="pagination" class="pagination-sm"></ul>
            </nav>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_add_hospital" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>添加体检套餐</strong></h4>
            </div>
            <div class="modal-body">
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Name" class="pull-right">套餐名称</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Name" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Hospital" class="pull-right">所属医院</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="Hospital" class="form-control">
                            @for (int i = 0; i < hos.Count; i++)
                            {
                                <option value="@hos[i].Id">@hos[i].Name</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="ComboTypeId" class="pull-right">套餐类型</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="ComboTypeId" class="form-control">
                            @for (int i = 0; i < combos.Count; i++)
                            {
                                <option value="@combos[i].Id">@combos[i].Name</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Price" class="pull-right">价格</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Price" class="form-control" type="number">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Appropriate" class="pull-right">适宜人群</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Appropriate" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Details" class="pull-right">套餐简介</label>
                    </div>
                    <div class="col-md-7 controls">
                        <textarea id="Details" class="form-control" style="height:180px;"></textarea>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Items" class="pull-right">体检项目</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="Items" class="form-control" multiple="multiple">
                            @for (int i = 0; i < items.Count; i++)
                            {
                                <option value="@items[i].Id">@items[i].Name</option>
                            }
                        </select>
                    </div>
                </div>
            </div>

            <div class="modal-footer">
                <div id="doing" style="float:left;display:none;">
                    <i class="fa fa-circle-o-notch fa-spin"></i><span> 处理中...</span>
                </div>
                <div id="success" style="float: left; display: none; ">
                    <i class="fa fa-check-square"></i><span> 保存成功！</span>
                </div>
                <div id="error" style="float: left; display: none; ">
                    <i class="fa fa-warning"></i><span> 保存失败！</span>
                </div>

                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn_model_add" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_edit" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>编辑单项体检</strong></h4>
            </div>
            <div class="modal-body">
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="NameEdit" class="pull-right">套餐名称</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="NameEdit" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="HospitalEdit" class="pull-right">所属医院</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="HospitalEdit" class="form-control">
                            @for (int i = 0; i < hos.Count; i++)
                            {
                                <option value="@hos[i].Id">@hos[i].Name</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="ComboTypeIdEdit" class="pull-right">套餐类型</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="ComboTypeIdEdit" class="form-control">
                            @for (int i = 0; i < combos.Count; i++)
                            {
                                <option value="@combos[i].Id">@combos[i].Name</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="PriceEdit" class="pull-right">价格</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="PriceEdit" class="form-control" type="number">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="AppropriateEdit" class="pull-right">适宜人群</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="AppropriateEdit" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="DetailsEdit" class="pull-right">套餐简介</label>
                    </div>
                    <div class="col-md-7 controls">
                        <textarea id="DetailsEdit" class="form-control" style="height:180px;"></textarea>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="ItemsEdit" class="pull-right">体检项目（多选）</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="ItemsEdit" class="form-control" multiple="multiple">
                            @for (int i = 0; i < items.Count; i++)
                            {
                                <option value="@items[i].Id">@items[i].Name</option>
                            }
                        </select>
                    </div>
                </div>
                <input type="hidden" id="curren_id" />
            </div>

            <div class="modal-footer">
                <div id="doing" style="float:left;display:none;">
                    <i class="fa fa-circle-o-notch fa-spin"></i><span> 处理中...</span>
                </div>
                <div id="success" style="float: left; display: none; ">
                    <i class="fa fa-check-square"></i><span> 保存成功！</span>
                </div>
                <div id="error" style="float: left; display: none; ">
                    <i class="fa fa-warning"></i><span> 保存失败！</span>
                </div>

                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn_model_edit" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>

@section Footer{
    <script type="text/javascript">
        $(function () {
            //多选插件初始化
            var ms_options = {
                selectAllText: '选择全部',
                nonSelectedText: '无体检项',
                nSelectedText: '个体检项',
                allSelectedText:'全部体检项'
            };
            $('#ItemsEdit').multiselect(ms_options);
            $('#Items').multiselect(ms_options);

            $(".delete").click(function () {
                var todo = confirm('确定要删除吗？');
                if (todo) {
                    var id = $(this).attr("data-id");
                    $.ajax({
                        url: '@Url.Action("PhysicalDelete", "Admin")',
                        type: 'post',
                        data: { id: id },
                        success: function (data) {
                            if (data.Code = 1) {
                                window.location.href = '@Url.Action("PhysicalCombo", "Admin")';
                                alert("删除成功！");
                            }
                            else {
                                alert("删除失败！");
                            }
                        }
                    });
                }
            });

            $(".edit").click(function () {
                var id = $(this).attr("data-id");
                $.ajax({
                    url: '@Url.Action("GetCombo", "Admin")',
                    data: { id: id },
                    type: 'post',
                    success: function (data) {
                        if (data.Code = 1) {
                            $("#curren_id").val(data.Data.Id);

                            $("#NameEdit").val(data.Data.Name);
                            $("#HospitalEdit").val(data.Data.HospitalId);
                            $("#ComboTypeIdEdit").val(data.Data.ComboTypeId);
                            $("#PriceEdit").val(data.Data.Price);
                            $("#AppropriateEdit").val(data.Data.Appropriate);
                            $("#DetailsEdit").val(data.Data.Details);
                            var selected = [];
                            for (var i = 0; i < data.Data.Items.length; i++) {
                                selected.push(data.Data.Items[i].Id);
                            }

                            $('#ItemsEdit').multiselect('select', selected);

                            $("#modal_edit").modal('show');
                        }
                    }
                });
            });

            //编辑
            $("#btn_model_edit").click(function () {
                var id = $("#curren_id").val();
                var Name = $("#NameEdit").val();
                var Hospital = $("#HospitalEdit").val();
                var ComboTypeId = $("#ComboTypeIdEdit").val();
                var Price = $("#PriceEdit").val();
                var Appropriate = $("#AppropriateEdit").val();
                var Details = $("#DetailsEdit").val();

                var selected = [];
                $('#ItemsEdit option:selected').each(function () {
                    selected.push($(this).val());
                });

                $.ajax({
                    url: '@Url.Action("EditCombo", "Admin")',
                    type: "post",
                    data: { id: id, name: Name, hospital: Hospital, comboTypeId: ComboTypeId, price: Price, appropriate: Appropriate, details: Details, items: selected },
                    success: function (data) {
                        if (data.Code = 1) {
                            $("#doing").hide();
                            $("#success").show();
                            setTimeout(function () {
                                $("#modal_add_course").modal('hide');
                                window.location.href = '@Url.Action("PhysicalCombo", "Admin")';
                            }, 1000);
                        }
                        else {
                            $("#doing").hide();
                            $("#error").show();
                        }
                    },
                    beforeSend: function (xhr) {
                        $("#btn_add_course").attr({ "disabled": "disabled" });
                        $("#doing").show();
                    },
                    complete: function (xhr, status) {
                        $("#doing").hide();
                    }
                });
            });

            $('#pagination').twbsPagination({
                totalPages: '@ViewBag.TotalPage',
                visiblePages: 5,
                first: "首页",
                prev: "上一页",
                next: "下一页",
                last: "尾页",
                href: '/Admin/PhysicalCombo?pageIndex={{pageNumber}}',
                hrefVariable: '{{pageNumber}}'
            });


            $('#modal_add_hospital').on('hidden.bs.modal', function (e) {
                $("#btn_add_course").removeAttr("disabled");

                $("#doing").hide();
                $("#success").hide();
                $("#error").hide();
                $("#name").val("");
                $("#des").val("");
            });

            //添加
            $("#btn_model_add").click(function () {
                var Name = $("#Name").val();
                var Hospital = $("#Hospital").val();
                var ComboTypeId = $("#ComboTypeId").val();
                var Price = $("#Price").val();
                var Appropriate = $("#Appropriate").val();
                var Details = $("#Details").val();

                var selected = [];
                $('#Items option:selected').each(function () {
                    selected.push($(this).val());
                });

                $.ajax({
                    url: '@Url.Action("PhysicalComboAdd", "Admin")',
                    type: "post",
                    data: { Name: Name, Hospital: Hospital, ComboTypeId: ComboTypeId, Price: Price, Appropriate: Appropriate, Details: Details, Items: selected },
                    success: function (data) {
                        if (data.Code = 1) {
                            $("#doing").hide();
                            $("#success").show();
                            setTimeout(function () {
                                $("#modal_add_course").modal('hide');
                                window.location.href = '@Url.Action("PhysicalCombo", "Admin")';
                            }, 1000);
                        }
                        else {
                            $("#doing").hide();
                            $("#error").show();
                        }
                    },
                    beforeSend: function (xhr) {
                        $("#btn_add_course").attr({ "disabled": "disabled" });
                        $("#doing").show();
                    },
                    complete: function (xhr, status) {
                        $("#doing").hide();
                    }
                });
            });
        });

    </script>
}
